<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <input type="text" id="ipt">
  <p id="op"></p>
  <script>
let obj={}
let val="初始值"
Object.defineProperty(obj,"txtVal",{
  get(){
    return val
  },
  set(newVal){
    ipt.value=newVal
    op.innerHTML=newVal
    val=newVal
  }
})
ipt.value=obj.txtVal
op.innerHTML=obj.txtVal

ipt.addEventListener('input',e=>{
  obj.txtVal=e.target.value
})
  </script>
</body>

</html>